Page({
  data: {
    encryptedData: '',
    houseInfo: '',
    url: '',
    validTime: '',
  },
  onLoad({ id, encryptedData }) {
    if (id) {
      this.getvisitorDelis(id)
    } else {
      this.getvisitorDelis2(encryptedData)
    }
  },
  async getvisitorDelis(id) {
    const res = await wx.http({ url: `/visitor/${id}` })
    // console.log(res);
    this.setData(res.data)
  },
  async getvisitorDelis2(encryptedData) {
    const res = await wx.http({ url: `/visitor/share/${encryptedData}` })
    // console.log(res);
    this.setData(res.data)
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.encryptedData,
      imageUrl: 'https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA166XZv.img?w=612&h=304&q=90&m=6&f=jpg&x=283&y=315&u=t',
    }
  },
  async OnsaveImage() {
    const { path } = await wx.getImageInfo({
      src: this.data.url
    })
    const res = await wx.saveImageToPhotosAlbum({
      filePath: path
    })
    console.log(res);
    wx.showToast({ title: '图片保存成功' })

  }
})
